import * as echarts from '../../plugin/ec-canvas/echarts';
// pages/login/login.js
//获取应用实例
const app = getApp()
const util = require('../../../utils/util.js')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    enter:'',
    studentGradeInOutList:[],
    loadding : 0
  },
  onLoad: function(options) {
    console.log("enter",options.enter)
    if(options.enter != undefined && options.enter !== null){
      wx.setStorageSync('enter', options.enter)
      this.setData({
        enter : options.enter
      })
    }
    let timeAfter  = util.formatTime(new Date())
    this.setData({
      curTime : timeAfter,
      loadding: 1
    })
    let timePre = util.formatTime2(new Date()) +" 00:00:00"
    console.log("timePre",timePre)
    let studentGradeInOutList = []
    let inTotal = 0 
    let outTotal = 0 
    let unrecordTotal = 0
    wx.request({
      url: app.baseUrl +"/WeChat/schoolMangement/getStudentInOutRecordDetail",
      method: 'POST',
      header:{
        "content-type":"application/json"
      },
      data: JSON.stringify({
        department: app.globalData.departmentId,
        timePre : timePre ,
        timeAfter : timeAfter
      }),
      dataType: 'json',
      success: res => {
        res.data.studentGradeInOutList.forEach((item,index) =>{
          studentGradeInOutList.push({
             grades : item.grades ,
             inTimes : item.inTimes ,
             outTimes : item.outTimes ,
             unrecord : item.unrecord ,
          })
          inTotal += item.inTimes
          outTotal += item.outTimes
          unrecordTotal += item.unrecord
        })
        this.setData({
          inTotal : inTotal,
          outTotal : outTotal,
          unrecordTotal : unrecordTotal,
          studentGradeInOutList : studentGradeInOutList,
          loadding: 0
        })
      }
    })
   
  },

  toInDetailStudentName:function(e){
    console.log("grade",e.currentTarget.dataset.grade)
    wx.navigateTo({
      url: '../inoutrecordStudentName/inoutrecordStudentName?grade='+e.currentTarget.dataset.grade,
    })
  },
  toOutDetailStudentName:function(e){
    console.log("grade",e.currentTarget.dataset.grade)
    wx.navigateTo({
      url: '../inoutrecordStudentName/inoutrecordStudentName?grade='+e.currentTarget.dataset.grade,
    })
  }
  


  
 
})

